import 'package:flutter_todo_2019/page/utils/utils.dart';
import 'package:flutter_todo_2019/test/imooc/flutter_layout_page.dart';
import 'package:flutter_todo_2019/test/imooc/less_group_page.dart';
import 'package:flutter_todo_2019/test/imooc/photo_app_page.dart';
import 'package:flutter_todo_2019/test/imooc/statefull_group_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_todo_2019/test/jike/CustomViewPage.dart';
import 'package:flutter_todo_2019/test/jike/HandlerMsgPage.dart';
import 'package:flutter_todo_2019/test/nd/TestChildPage.dart';
import 'package:flutter_todo_2019/test/nd/TestStickListPage.dart';
import 'package:flutter_todo_2019/test/nd/TestStickyPage.dart';

import 'app_lifecycle.dart';
import 'flutter_widget_lifecycle.dart';
///TODO 小Demo集合
class RouteNavigator extends StatefulWidget {
  @override
  _RouteNavigatorState createState() => _RouteNavigatorState();
}

class _RouteNavigatorState extends State<RouteNavigator> {
  bool byName = false;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("小练习",
            style: TextStyle(color: Colors.white, fontSize: 18)),
        centerTitle: true,
        actions: <Widget>[
          new IconButton(
              icon: ImageIcon(AssetImage(Utils.getImgPath("icon_more"))),
              onPressed: () {}),
        ],
      ),
      body: Container(
        color: Colors.white,
        width: double.infinity,
        child: Column(
          children: <Widget>[
            Text('${byName ? '' : '不'}通过路由名跳转', style: TextStyle( fontSize: 18)),
            _item('StatelessWidget与基础组件', LessGroupPage(), 'less'),
            _item('StatefulWidget与基组件', StatefulGroup(), 'ful'),
            _item('Handler发送Msg Bus使用', HandlerMsgPage(title: "Msg",), 'handlermsg'),
            _item('如何进行Flutter布局开发', FlutterLayoutPage(), 'layout'),
            _item('如何进行CustomView开发', CustomViewPage(title: "Custom UI"), 'custom'),
            _item('Flutter页面生命周期', WidgetLifecycle(), 'widgetLifecycle'),
            _item('Flutter应用生命周期', AppLifecycle(), 'appLifecycle'),
            _item('【实战尝鲜】拍照APP开发', PhotoApp(), 'photo'),
            _item('Child View Page', TestChildPage(), 'childpage'),
            _item('Sticky Page', StickyPage(), 'stickypage'),
            _item('Sticky List Page', TestHomePage(), 'testhomepage'),


          ],
        ),
      ),
    );

    ;
  }

  _item(String title, page, String routeName) {
    return Container(
      child: RaisedButton(
        onPressed: () {
          if (byName) {
            Navigator.pushNamed(context, routeName);
          } else {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => page));
          }
        },
        child: Text(title),
      ),
    );
  }
}
